package com.lebang.service.sys;

import com.lebang.domain.PkgEarnInfo;
import com.lebang.example.PkgEarnInfoExample;
import com.lebang.mapper.PkgEarnInfoMapper;
import com.lebang.service.BaseService;
import com.lebangweb.common.TextUtil;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * pkg_earn_info
 *
 * @Author hwq
 * @Date 2020-06-17
 */
@Service
public class PkgEarnInfoService extends BaseService<PkgEarnInfo, Integer, PkgEarnInfoExample> {
    @Autowired
    private PkgEarnInfoMapper pkgEarnInfoMapper;

    /**
     * 验证能否做每日必赚
     * true 可以
     * @param packName
     * @return
     */
    public boolean checkPkgName(String packName,String appName){
        if(NumberUtils.isNumber(packName)){
            return false;
        }
        if(TextUtil.isEmpty(packName)){
            return false;
        }
        PkgEarnInfo pkgEarnInfo= pkgEarnInfoMapper.selectByPkgName(packName);
        if(pkgEarnInfo==null){
            PkgEarnInfo vo=new PkgEarnInfo();
            vo.setCreateTime(LocalDateTime.now());
            vo.setModifyTime(LocalDateTime.now());
            vo.setHasDeleted(0);
            vo.setPkgName(packName);
            vo.setAppName(appName);
            vo.setIcon("");
            vo.setOpenDownload(1);
            vo.setOpenClick(1);
            vo.setCheckUser("");
            this.insertModel(vo);
            return true;
        }else {
            pkgEarnInfoMapper.updateById(pkgEarnInfo.getId());
            return pkgEarnInfo.getOpenDownload().equals(1);
        }
    }


    public void enableList(List<String> stringList, Integer type) {
        pkgEarnInfoMapper.enableList(stringList,type);
    }
}
